package team.seekers.hula.question.point.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.VisibilityUpdateDTO;
import team.seekers.hula.common.entity.enums.question.PointOrderEnum;
import team.seekers.hula.question.point.entity.dto.PointAddDTO;
import team.seekers.hula.question.point.entity.dto.PointUpdateDTO;
import team.seekers.hula.question.point.entity.vo.PointInfoVO;
import team.seekers.hula.question.point.entity.vo.PointListVO;
import team.seekers.hula.question.point.service.PointFireService;
import team.seekers.hula.question.point.service.PointService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hbc
 * @since 2021-02-15
 */
@Controller
@ApiResponseBody
@RequestMapping("/point")
public class PointController {

    @Resource
    private PointService pointService;

    @Resource
    private PointFireService pointFireService;

    @PostMapping("/add")
    public void add(@RequestBody PointAddDTO addVO){
        pointService.add(addVO);
    }

    @PostMapping("/update/info")
    public void updateInfo(@RequestBody PointUpdateDTO updateDTO){
        pointService.updateInfo(updateDTO);
    }

    @PostMapping("/update/visibility")
    public void updateVisibility(@RequestBody VisibilityUpdateDTO updateDTO){
        pointService.updateVisibility(updateDTO);
    }

    @GetMapping("/info")
    public PointInfoVO info(@RequestParam String id){
        return pointService.getInfoVO(id);
    }

    // 如果提出这个观点的人连回答都没有了，那么普通提问者或者观点提出者可以将其删除,
    @GetMapping("/delete")
    public void delete(@RequestParam("PointId") String id){
        pointService.delete(id);
    }


    @GetMapping("/list")
    public List<PointListVO> listByQuestionIdOrderByHeat(@RequestParam String questionId,
                                                         @RequestParam PointOrderEnum sortBy){
        List<PointListVO> VOList = pointService.list(questionId,sortBy);
        return VOList;
    }

    @GetMapping("/fire")
    public void info(@RequestParam String id, @RequestParam Integer fire){
        pointFireService.firePoint(id,fire);
    }

}

